﻿var focusedIt = true;
function checkBeforeWriteReview(object) {
    var IsAllowWriteRev = '<%= Session["IsAllowWriteRev"] %>';
    if (IsAllowWriteRev == "false" && focusedIt) {
        focusedIt = false;
        object.disabled = true;
        alert("დღეში შესაძლებელია მხოლოდ ერთი რევიოს დამატება თითოეულ კომპანიაზე!");
    }
}

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.search);
    if (results == null)
        return "";
    else
        return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function recordOutboundLink(link) {
    try {
        var strlink = "http://" + link;
        window.open(link);
        // pageTracker._trackEvent(category, action);
        //setTimeout('document.location = "' + link.href + '"', 100)
    } catch (err) { }
}

//--google map!!!
var map = null;
var geocoder = null;

function initialize() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("ContentPlaceHolder1_map_div"));
        map.setCenter(new GLatLng(41.709701, 44.791918), 1);
        map.setUIToDefault();
        geocoder = new GClientGeocoder();
    }
}

function showAddress(address) {
    if (geocoder) {
        geocoder.getLatLng(
                address,
                function (point) {
                    if (!point) {
                        //alert(address + " not found");
                    } else {
                        map.setCenter(point, 15);
                        var marker = new GMarker(point, { draggable: true });
                        map.addOverlay(marker);
                        GEvent.addListener(marker, "dragend", function () {
                            marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
                        });
                        GEvent.addListener(marker, "click", function () {
                            marker.openInfoWindowHtml(marker.getLatLng().toUrlValue(6));
                        });
                        GEvent.trigger(marker, "click");
                    }
                });
    }
}

$(document).ready(function () {
    initialize();
    try {
        showAddress($("#CompanyAddress").text());
    } catch (e) {
        $("#ContentPlaceHolder1_map_div").text($("#CompanyAddress").text());
    }
    $("#popup").fancybox({
        'width': '35%',
        'height': '30%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'hideOnContentClick': false,
        'showCloseButton': true,
        'scrolling': "no",
        'type': 'iframe',
        'onClosed': function () {
            window.location = 'singlecompany.aspx?id=' + getParameterByName("id");
        }
    });

    $("#ContentPlaceHolder1_ReviewText").keyup(function () {
        var crnt = $(this);
        crnt.css('color', 'Black');
        if (crnt.val() == '') {
            crnt.css('color', '#A8A8A8');
        }

        var qnt = $("#symbolsq");
        var spanText = $("#spanMin");
        var spanC = $("#symbolt");
        var smb = 30 - crnt.val().length;
        if (smb <= 0) {
            spanText.hide();
            spanC.css('color', '#a5bd52');
        } else {
            spanText.show();
            spanC.css('color', '#5f5f5f');
        }
        qnt.text(Math.abs(smb));
    });


    $("a[name=DeleteReviewAdmin]").click(function (e) {
        e.preventDefault();
        var revioid = $(this).prev().attr("revid");
        var params = "RemoveReview|" + revioid;
        var ggp = $(this).parent().parent();
        ggp.next().next().hide('slow');
        ggp.next().hide('slow');
        ggp.prev().hide('slow');
        ggp.hide('slow');
        CallServer(params, "");
    });
    $(".like_cont a[name=like]").click(function (e) {
        var t = $(this);
        t.find("img").attr("src", "images/like_icon.png");
        var ls = parseInt(t.next().next().text()) + 1;
        t.next().next().text(ls);
        var params = "Like|" + t.attr("lik");
        CallServer(params, "");
        t.off();
        e.preventDefault();
    });
    $(".like_cont a[name=dislike]").click(function (e) {
        var t = $(this);
        t.find("img").attr("src", "images/dislike_icon.png");
        var ls = parseInt(t.next().text()) - 1;
        t.next().text(ls);
        var params = "DisLike|" + t.attr("dislik");
        CallServer(params, "");
        t.off();
        e.preventDefault();
    });
    $("#showUploader").click(function (e) {
        e.preventDefault(); $(".score_txt").slideToggle();
    });
    $("#Submit").click(function (e) {
        var isClicked = false, isError = false, texterror = "";
        if ($("#ContentPlaceHolder1_ReviewText").val().length <= 30) { isError = true; texterror = "შეიყვანეთ მინიმუმ 30 სიმბოლო"; }
        if (cRating.rating == 0) { isError = true; texterror = "მონიშნეთ რეიტინგი"; }
        if ($("#ContentPlaceHolder1_ReviewText").val() == "" || $("#ContentPlaceHolder1_ReviewText").val() == "დაწერეთ რას ფიქრობთ...") { isError = true; texterror = "შეავსეთ ტექსტით"; }
        $("#ContentPlaceHolder1_HidnField").val(cRating.rating);
        if (isError == true) { alert(texterror); e.preventDefault(); }
        else { if (!isClicked) { isClicked = true; } else { e.preventDefault(); } }
    });
    $("a[rel=imagegallery]").fancybox({ helpers: { thumbs: { width: 50, height: 50}} });
});
function ReceiveServerData(arg, context) { var parts = arg.split("|"); switch (parts[0]) { case "Success": { break; } case "Error": break; case "Fail": break; default: break; } }
    